﻿<%@ Page Language="C#" MasterPageFile="~/SiteUser.master" AutoEventWireup="true"
    CodeFile="ChangePassword.aspx.cs" Inherits="SiteUserChangePassword" Title="Change Password" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<%--    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>--%>
    <div class="elements_inner_wrapper">
        <div id="contentBody">
            <asp:Panel runat="server" ID="pnlChangePassword" DefaultButton="btnSubmit">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="30%">
                        Current Password
                    </td>
                    <td width="70%">
                        <asp:TextBox ID="txtOldPassword" runat="server" MaxLength="20" Width="120px" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rfvOldPassword" runat="server" ControlToValidate="txtOldPassword"
                            Display="Dynamic" ErrorMessage="Require current password." Text="Require current password."
                            ValidationGroup="customer"></asp:RequiredFieldValidator>
                        <%--<asp:CustomValidator ID="csvOldPasswordLength" runat="server" ClientValidationFunction="CheckPasswordLength"
                            ControlToValidate="txtOldPassword" Display="Dynamic" ErrorMessage="Password length should be at least 8."
                            OnServerValidate="CheckPasswordLength" Text="Password length should be at least 8."
                            ValidationGroup="customer"></asp:CustomValidator>--%>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        New Password
                    </td>
                    <td>
                        <asp:TextBox ID="txtNewPassword" runat="server" MaxLength="20" Width="120px" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rfvNewPassword" runat="server" ControlToValidate="txtNewPassword"
                            Display="Dynamic" ErrorMessage="Require new password." Text="Require new password."
                            ValidationGroup="customer"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="revNewPassword" runat="server" ControlToValidate="txtNewPassword"
                            ValidationExpression="^\w*(?=\w*\d{2})(?=\w*[a-z]{2})(?=\w*[A-Z]{2})\w{8,20}$" Display="Dynamic"
                            ErrorMessage="Password must be two upper, two lower, two digits and (8-20) characters long." ValidationGroup="customer"/>
                        <%--<asp:CustomValidator ID="csvNewPassword" runat="server" ClientValidationFunction="CheckPasswordLength"
                            ControlToValidate="txtNewPassword" Display="Dynamic" ErrorMessage="Password length should be at least 8."
                            OnServerValidate="CheckPasswordLength" Text="Password length should be at least 8."
                            ValidationGroup="customer"></asp:CustomValidator>--%>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        Confirm Password
                    </td>
                    <td>
                        <asp:TextBox ID="txtConfirmPassword" runat="server" MaxLength="20" Width="120px"
                            TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rfvConfirmPassword" runat="server" ControlToValidate="txtConfirmPassword"
                            Display="Dynamic" ErrorMessage="Required confirm password." Text="Required confirm password."
                            ValidationGroup="customer"></asp:RequiredFieldValidator>
                        <asp:CompareValidator ID="csvConfirmPassword" runat="server" ControlToCompare="txtNewPassword"
                            ControlToValidate="txtConfirmPassword" Display="Dynamic" ErrorMessage="New and confirm password must be same."
                            Text="New and confirm password must be same." ValidationGroup="customer"></asp:CompareValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        Security Check
                    </td>
                    <td>
                        <asp:UpdatePanel runat="server" ID="uplCAPCHA">
                            <ContentTemplate>
                                <div style="display: block; float: left;">
                                    <asp:Image ID="imgCAPTCHA" ImageUrl="~/captcha/Random.gif" runat="server" />
                                </div>
                                <asp:ImageButton ID="btnNewImage" runat="server" OnClick="btnNewImage_Click" ImageUrl="~/images/icons/refresh.gif"
                                    ToolTip="Reload" AlternateText="Refresh" />
                                <%--<asp:Label ID="Label1" Text="" runat="server"></asp:Label>--%>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        <asp:UpdateProgress AssociatedUpdatePanelID="uplCAPCHA" DisplayAfter="100" runat="server"
                            ID="udpCAPTCHA">
                            <ProgressTemplate>
                                <img src="../images/loading7.gif" alt="Loading..." /><br />
                            </ProgressTemplate>
                        </asp:UpdateProgress>
                    </td>
                </tr>
                <tr>
                    <td>
                        Text in Box
                    </td>
                    <td>
                        <asp:TextBox ID="txtSecurityCode" MaxLength="20" Width="120px" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rfvSecurityCheck" runat="server" ControlToValidate="txtSecurityCode"
                            Display="Dynamic" ErrorMessage="Require security check text." Text="Require security check text."
                            ValidationGroup="customer"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Change Password"
                            ValidationGroup="customer" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <asp:Label ID="lblMessage" ForeColor="Red" runat="server"></asp:Label>
                    </td>
                </tr>
            </table>
            </asp:Panel>
        </div>
    </div>

    <script type="text/javascript">
        function CheckPasswordLength(source, arguments) {
            //var corglen = arguments.Value;
            var cval = arguments.Value;
            var bValid = true;
            var chList = new Array(20);
            var ctrlsource = document.getElementById(source.id);

            //alert("ORG LEN : " + corglen.length + " AFTER : " + cval.length);
            if (cval.indexOf(' ') != -1 || cval.indexOf('\'') != -1
                        || cval.indexOf('\"') != -1 || cval.indexOf('~') != -1) {
                if (ctrlsource.textContent) {
                    ctrlsource.textContent = "Password include invalid character or space!";
                }
                else {
                    ctrlsource.innerText = "Password include invalid character or space!";
                }

                ctrlsource.errormessage = "Password include invalid character or space!";
                bValid = false;
            }
            else if (cval.length < 8) {
                //ctrlsource.innerText = "Password length should be at least 6";
                if (ctrlsource.textContent) {
                    ctrlsource.textContent = "Password length should be at least 8";
                }
                else {
                    ctrlsource.innerText = "Password length should be at least 8";
                }

                ctrlsource.errormessage = "Password length should be at least 8";
                bValid = false;
            }
            else if (cval.length > 20) {
                bValid = false;
                //ctrlsource.innerText = "Password length should not be over 20!";
                if (ctrlsource.textContent) {
                    ctrlsource.textContent = "Password length should not be over 20!";
                }
                else {
                    ctrlsource.innerText = "Password length should not be over 20!";
                }
                ctrlsource.errormessage = "Password length should not be over 20!";
            }
            else {
                bValid = true;
            }
            //alert(cval);
            //if (isNaN(cval)){
            //    bValid = false;
            //} 


            //alert(bValid);
            arguments.IsValid = bValid;
            return;
        }
    </script>

</asp:Content>
